package com.elm.app;

import com.elm.entity.Business;
import com.elm.view.BusinessView;
import com.elm.view.FoodView;
import com.elm.view.impl.BusinessViewImpl;
import com.elm.view.impl.FoodViewImpl;

import com.elm.util.ConsoleUtil;

public class ElmBusinessEntry {
    public static void main(String[] args) {
        run();
    }

    public static void run() {
        BusinessView businessView = new BusinessViewImpl();
        FoodView foodView = new FoodViewImpl();

        ConsoleUtil.printDivider("饿了么商家管理系统");

        Business business = businessView.login();

        if (business != null) {
            ConsoleUtil.printSuccess("登录成功！欢迎商家：" + business.getBusinessName());
            int menu = 0;
            while (menu != 6) {
                ConsoleUtil.printMenu(
                        "========= 商家管理菜单 =========",
                        "查看商家信息",
                        "修改商家信息",
                        "修改密码",
                        "查看食品信息",
                        "修改食品信息",
                        "退出系统"
                );
                menu = ConsoleUtil.readInt();

                switch (menu) {
                    case 1:
                        businessView.showBusiness(business.getBusinessId());
                        break;
                    case 2:
                        businessView.editBusiness(business.getBusinessId());
                        break;
                    case 3:
                        businessView.updateBusinessByPassword(business.getBusinessId());
                        break;
                    case 4:
                        foodView.listFoodByBusinessId(Integer.valueOf(business.getBusinessId()));
                        break;
                    case 5:
                        foodManager(Integer.valueOf(business.getBusinessId()));
                        break;
                    case 6:
                        ConsoleUtil.printDivider("欢迎下次使用饿了么商家管理系统");
                        break;
                    default:
                        ConsoleUtil.printError("没有这个选项！");
                        break;
                }
            }
        } else {
            ConsoleUtil.printError("商家编号或密码错误！");
        }
    }

    private static void foodManager(Integer businessId) {
        FoodView foodView = new FoodViewImpl();
        int menu = 0;
        while (menu != 5) {
            ConsoleUtil.printMenu(
                    "========= 食品管理菜单 =========",
                    "查看所有食品",
                    "新增食品",
                    "修改食品",
                    "删除食品",
                    "返回上一级"
            );
            menu = ConsoleUtil.readInt();

            switch (menu) {
                case 1:
                    foodView.listFoodByBusinessId(businessId);
                    break;
                case 2:
                    foodView.saveFood(businessId);
                    break;
                case 3:
                    foodView.updateFood(businessId);
                    break;
                case 4:
                    foodView.removeFood(businessId);
                    break;
                case 5:
                        ConsoleUtil.printMessage("返回商家管理主菜单。");
                    break;
                default:
                    ConsoleUtil.printError("没有这个选项！");
                    break;
            }
        }
    }
}
